﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ManageAccount : System.Web.UI.Page
{
    ManagePatron patronInfo;
    Patron patron;
    string lib;

    void Page_PreInit(object sender, System.EventArgs e)
    {
        String theme = (String)Session["theme"];
        if (theme == null)//if session timed out
        {
            ManageLibrary manager = new ManageLibrary();
            Library lib = manager.getLibrary(Request.QueryString["id"]);
            if (lib == null)//if library not found
                lib.Theme = "Blue";
            Session["theme"] = lib.Theme;
            theme = lib.Theme;
        }
        Page.Theme = theme.Trim();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        patronInfo = new ManagePatron();
        patron = (Patron)Session["Patron"];
        lblPersonID.Text = patron.PersonID.ToString();
        GridView1.Visible = true;
        lib = Request.QueryString["id"].ToString();
        if (!IsPostBack)
        {
            GridView1.DataBind();
        }

    }

    protected void GridView1_RowUpdated(object sender,GridViewUpdatedEventArgs e)
    {
        if (e.Exception != null)
        {
            lblConfirm.Text = "A database error has occured. <br /><br /> Message: " + e.Exception.Message;
            e.ExceptionHandled = true;
            e.KeepInEditMode = true;
        }
        else if (e.AffectedRows == 0)
            lblConfirm.Text = "Another user may have updated that record. <br /> Please try again.";
        else
            lblConfirm.Text = "Your record has been saved";
        GridView1.DataBind();
    }

    protected void GridView2_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {
        if (e.Exception != null)
        {
            lblConfirm.Text = "A database error has occured. <br /><br /> Message: " + e.Exception.Message;
            e.ExceptionHandled = true;
            e.KeepInEditMode = true;
        }
        else if (e.AffectedRows == 0)
            lblConfirm.Text = "Another user may have updated that record. <br /> Please try again.";
        else
            lblConfirm.Text = "Your record has been saved";
        GridView1.DataBind();
    }

    protected void btnFinish_Click(object sender, EventArgs e)
    {
        Response.Redirect("PatronView.aspx?id=" + lib);
    }
}
